#include <iostream>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
#include <unordered_set>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
const int N=1e6+10;
int prime[N];
int v[N];
int m=0;
void get_prime(int n)
{
	for (int i = 2; i<=n; i++) 
	{
	    if(v[i] == 0) 
	    { 
		    v[i] = i;
		    prime[++m] = i;
	    }
	    for (int j = 1; j <= m; j++) 
	    {
		    if (prime[j] > v[i] || prime[j] > n/i) break;
		    v[i*prime[j]] = prime[j];
	    } 
    }
}

int main()
{
	get_prime(10000);
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		if(n==0) break;
		int cnt=0;
		for(int i=1;prime[i]<=n/3;i++)
		{
			for(int j=i;n-prime[i]-prime[j]>=prime[j];j++)
			{
				if(n-prime[i]-prime[j]==v[n-prime[i]-prime[j]]) cnt++;
			}
		}
		printf("%d\n",cnt);
	}

	return 0;
}

